<template>
  <div class="all">
    <table width="100%" cellspacing="0">
      <thead>
        <tr>
          <th width="10px"></th>
          <th width="40px">等级ID</th>
          <th width="150px">等级名称</th>
          <th width="150px">赚取下限</th>
          <th width="150px">赚取上限</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(val,name) in list">
          <td></td>
          <td><input type="text" size="3"  v-model="val.levelId"></td>
          <td><input type="text" style="width: 120px;"  v-model="val.name"></td>
          <td><input type="text" style="width: 120px;" v-model="val.min"></td>
          <td><input type="text" style="width: 120px;" v-model="val.max"></td>
          <td></td>
        </tr>

        <tr>
        <td>增加</td>
          <td><input type="text" size="3" v-model="add.levelId"></td>
          <td><input type="text" style="width: 120px;" v-model="add.name"></td>
          <td><input type="text" style="width: 120px;" v-model="add.min"></td>
          <td><input type="text" style="width: 120px;" v-model="add.max"></td>
          <td></td>
        </tr>
      </tbody>
    </table>
    <button @click="submit()">保存</button>
  </div>
</template>

<script>
  export default{
     inject:["reload"],
    data(){
      return{
        add:{},
        list:[],
      }
    },
    methods:{
      submit(){
        if(Object.keys(this.add).length==4&& Object.values(this.add).indexOf('')==-1){
             this.add.levelId=Number(this.add.levelId)
             this.add.min=Number(this.add.min)
             this.add.max=Number(this.add.max)
             this.list.push(this.add)
        }
         this.Postdata('admin/anchorLevel/mod',this.list)
      },
      Postdata(url,e){
        var _this=this
        if(e){
         e.forEach(function(val,key){
            val.levelId=Number(val.levelId)
            val.min=Number(val.min)
            val.max=Number(val.max)
          })
        }
        this.$axios({
                method: "POST",
                url: '/api/'+url,
                headers: {'Content-Type': 'application/json'},
                data: {
                          adminName:_this.$cookies.get('adminName'),
                          token:_this.$cookies.get('token'),
                          anchorLevels:e
                      },
               }).then(function(res){
                 if(res.data.code==0){
                   if(res.data.data!=null){
                     _this.list=res.data.data.anchorLevelList
                   }else{
                     _this.$alert('操作成功', '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                          _this.reload()
                        }
                      });
                   }
                 }else{
                   _this.$alert('操作失败,请重试', '提示', {
                      confirmButtonText: '确定',
                      callback: action => {
                     
                      }
                    });
                 }
               })
      }
    },
    mounted(){
    this.Postdata('admin/anchorLevel/getAll')

    }
  }
</script>

<style scoped>
th{
      height: 30px;
      background: #eef3f7;
      border-bottom: 1px solid #d5dfe8;
      font-weight: normal;
}
td{
  border-bottom: #eee 1px solid;
      padding-top: 5px;
      padding-bottom: 5px;
}
td input{
margin: auto;
display: block;
text-align: center;
box-shadow:0 0 0 0 rgba(238,238,238,0.5)
}
</style>
